package com.enzoism.springboot.dive.controller;

import com.enzoism.springboot.dive.dao.UserDao;
import com.enzoism.springboot.dive.model.UserModel;

import javax.servlet.http.HttpServletRequest;

/**
 * 模拟用户登录
 * 1）当前是模拟，即使数据库可用，当前的逻辑也不可用
 * 2）对象没有注入大容器中，也没有添加标注
 */
public class UserController {
    private final UserDao userDao;

    public UserController(UserDao userDao) {
        this.userDao = userDao;
    }

    // 模拟用户登录
    public String getUsrMsg(HttpServletRequest request) {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String redirect = "login";
        try {
            UserModel msgByCondition = userDao.getMsgByCondition(username, password);
            if (null != msgByCondition) {
                redirect = "index";
            }
        } catch (Exception e) {
            redirect = "500";
        }
        return redirect;
    }
}
